package com.abner.basis.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author yuhui
 * @Date: 2024/3/22
 */
public class ExecutorsDemo {

    public static void main(String[] args) {

        // 一池n线程
//        ExecutorService executorService = Executors.newFixedThreadPool(5);

        // 一池一线程
//        ExecutorService executorService = Executors.newSingleThreadExecutor();

        // 一池可扩容线程
        ExecutorService executorService = Executors.newCachedThreadPool();

        try {
            for (int i = 0; i < 8; i++) {
                executorService.execute(() -> System.out.println(Thread.currentThread().getName()+"正在办理业务"));
            }
        }finally {
            executorService.shutdown();
        }
    }
}
